XKH_T_lua = class({})
LinkLuaModifier( "modifier_XKH_T_lua", LUA_MODIFIER_MOTION_NONE )

--------------------------------------------------------------------------------
function XKH_T_lua:OnAbilityPhaseStart()
	self:GetCaster():StartGesture( ACT_DOTA_ATTACK )
	return true
end

--------------------------------------------------------------------------------
function XKH_T_lua:OnAbilityPhaseInterrupted()
	self:GetCaster():RemoveGesture( ACT_DOTA_ATTACK )
end

--------------------------------------------------------------------------------
function XKH_T_lua:OnOwnerDied()
	self:GetCaster():RemoveGesture( ACT_DOTA_ATTACK )
end

--------------------------------------------------------------------------------

function XKH_T_lua:OnSpellStart()
	local hTarget = self:GetCursorTarget()
	if hTarget ~= nil then
		if ( not hTarget:TriggerSpellAbsorb( self ) ) then
			local stuntime = self:GetSpecialValueFor("stuntime")
			hTarget:AddNewModifier( self:GetCaster(), self, "modifier_XKH_T_lua", { duration = stuntime } )

			KnockBack(self:GetCaster(),hTarget,0,0,1.3,0,500,true,300)

			local damagetable={
						attacker=self:GetCaster(),
						victim=hTarget,
						damage=self:GetAbilityDamage(),
						damage_type=self:GetAbilityDamageType()
						}
			ApplyDamage(damagetable)

			local nFXIndex = ParticleManager:CreateParticle("particles/units/heroes/hero_tusk/tusk_walruspunch_start.vpcf", PATTACH_WORLDORIGIN, self:GetCaster() )
			ParticleManager:SetParticleControl(nFXIndex, 0, hTarget:GetAbsOrigin())
			ParticleManager:ReleaseParticleIndex( nFXIndex )
			nFXIndex = ParticleManager:CreateParticle("particles/units/heroes/hero_centaur/centaur_warstomp.vpcf", PATTACH_WORLDORIGIN, self:GetCaster() )
			ParticleManager:SetParticleControl(nFXIndex, 0, hTarget:GetAbsOrigin())
			ParticleManager:ReleaseParticleIndex( nFXIndex )

			EmitSoundOn( "Hero_Tusk.WalrusPunch.Target", hTarget )
			hTarget:SetContextThink(DoUniqueString("XKH_Tlua"),
				function()
					local vector = hTarget:GetAbsOrigin()
					if GetGroundPosition(vector,hTarget).z - vector.z == 0 then
						nFXIndex = ParticleManager:CreateParticle("particles/units/heroes/hero_centaur/centaur_warstomp.vpcf", PATTACH_WORLDORIGIN, self:GetCaster() )
						ParticleManager:SetParticleControl(nFXIndex, 0, hTarget:GetAbsOrigin())
						ParticleManager:ReleaseParticleIndex( nFXIndex )
						nFXIndex = ParticleManager:CreateParticle("particles/econ/items/earthshaker/egteam_set/hero_earthshaker_egset/earthshaker_echoslam_start_fallback_mid_egset.vpcf", PATTACH_WORLDORIGIN, self:GetCaster() )
						ParticleManager:SetParticleControl(nFXIndex, 0, hTarget:GetAbsOrigin())
						ParticleManager:ReleaseParticleIndex( nFXIndex )
						EmitSoundOn("Hero_Brewmaster.thunderclap", hTarget)
						return nil
					end
					return 0
				end
			, 0)
		end
	end
end

